package com.pactera.madp.cp.controller.sidebar.employee;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.cp.api.vo.employee.EmployeeDoVO;
import com.pactera.madp.cp.api.vo.employee.EmployeeInfoVo;
import com.pactera.madp.cp.api.vo.employee.EmployeeInfoWechatVO;
import com.pactera.madp.cp.common.util.WxApiUtils;
import com.pactera.madp.cp.handler.CorpContextHolder;
import com.pactera.madp.cp.service.EmployeeDoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/employee-info")
@Api(value = "employee-info", tags = "访问用户管理")
public class EmployeeInfoController {

    @Resource
    private EmployeeDoService employeeDoService;

    /**
     * 通过code获取访问用户身份
     * @return
     */
    @GetMapping("info")
    @ApiOperation(value = "通过code获取访问用户身份")
    public R<EmployeeInfoVo> getUserInfo(
            @RequestParam("code") String code,
            @RequestParam("agentId") Integer agentId
    ) {
        //用户信息查询
        String wxUserId = WxApiUtils.requestWxUserIdApi(CorpContextHolder.getCorpId(), agentId, code);
        if(wxUserId == null) {
            return R.failed("获取用户信息失败");
        }
        EmployeeInfoVo vo = new EmployeeInfoVo();
        vo.setWxUserId(wxUserId);
        return R.ok(vo);
    }

    @GetMapping("/remind-do")
    @ApiOperation(value = "获取待办相关数据")
    public R<Page<List<EmployeeDoVO>>> remindInfoDo(@RequestParam String wxUserId, Page page) {
        return R.ok(employeeDoService.getInfoDoPage(wxUserId, page));
    }

    @GetMapping("/remind-follow")
    @ApiOperation(value = "获取跟进相关数据")
    public R<Page<EmployeeInfoWechatVO>> remindInfoFollow(@RequestParam String wxUserId, Page page) {
        return R.ok(employeeDoService.getInfoFollowPage(wxUserId, page));
    }

    @GetMapping("/remind-interaction")
    @ApiOperation(value = "获取待办互动相关数据")
    public R<Page<EmployeeInfoWechatVO>> remindInfoInteraction(@RequestParam String wxUserId, Page page) {
        return R.ok(employeeDoService.getInfoInteractionPage(wxUserId, page));
    }

}
